package vn.sunnet.backviet01.game.coloa.util;

import java.util.Comparator;
import java.util.List;

import org.anddev.andengine.util.sort.InsertionSorter;

import vn.sunnet.backviet01.game.coloa.human.enemy.Enemy;

public class YEnemySorter extends InsertionSorter<Enemy> {
	// ===========================================================
	// Constants
	// ===========================================================

	private static YEnemySorter INSTANCE;

	// ===========================================================
	// Fields
	// ===========================================================

	private final Comparator<Enemy> mZIndexComparator = new Comparator<Enemy>() {
		@Override
		public int compare(final Enemy pEnemyA, final Enemy pEnemyB) {
			return (int)(pEnemyA.getYSort() - pEnemyB.getYSort());
		}
	};

	// ===========================================================
	// Constructors
	// ===========================================================

	private YEnemySorter() {

	}

	public static YEnemySorter getInstance() {
		if (INSTANCE == null) {
			INSTANCE = new YEnemySorter();
		}
		return INSTANCE;
	}

	// ===========================================================
	// Getter & Setter
	// ===========================================================

	// ===========================================================
	// Methods for/from SuperClass/Interfaces
	// ===========================================================

	// ===========================================================
	// Methods
	// ===========================================================

	public void sort(final Enemy[] pEntities) {
		this.sort(pEntities, this.mZIndexComparator);
	}

	public void sort(final Enemy[] pEntities, final int pStart, final int pEnd) {
		this.sort(pEntities, pStart, pEnd, this.mZIndexComparator);
	}

	public void sort(final List<Enemy> pEntities) {
		this.sort(pEntities, this.mZIndexComparator);
	}

	public void sort(final List<Enemy> pEntities, final int pStart, final int pEnd) {
		this.sort(pEntities, pStart, pEnd, this.mZIndexComparator);
	}
}
